home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / MWCC03.ZIP / WINTASK.ZIP / WINTASK.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-18  |  18KB  |  555 lines

  1. {**********************************************************************}
  2. {*                                                                    *}
  3. {*          Microworks Sample Application                                        *}
  4. {*                                                                    *}
  5. {*         for Borland Pascal v7.0 and Turbo Pascal for Windows v1.5           *}
  6. {*                                                                    *}
  7. {*     Copyright 1992-93 Jeff Franks (Microworks) Sydney, Australia.  *}
  8. {*                                                                    *}
  9. {*         You are free to use, modify, reproduce and distribute the      *}
  10. {*         Sample Files (and/or any modified version) in any way you      *}
  11. {*         find useful.                                                                *}
  12. {*                                                                    *}
  13. {**********************************************************************}
  14.  
  15. {*** Introduction
  16.  
  17.     Application := System Task List
  18.  
  19.     Files       := Wintask.exe, Wintask.pas, Wintask.res
  20.  
  21.     Requires    := MObjects and MWCC.dll
  22.  
  23.     Purpose     := Wintask shows you how to,
  24.  
  25.                                  1. Use the EnumWindows function to set up a task list.
  26.  
  27.                                  2. Set up an ownerdraw list box and fill it with icons.
  28.  
  29.                                  3. Use some of the objects in the MWCC library.
  30.  
  31.     Tabs        := 2
  32.  
  33.     Screen      := 800 * 600
  34.  
  35.     Date        := August 1993.
  36.  
  37.     Wintask is a Task Manager application that with a little work could be made into one
  38.     of the best task managers around. Its main purpose is to show you how to use an
  39.     ownerdraw list box and fill it with icons. Wintask also shows off some of the objects
  40.     in the MWCC library (a recessed  list box, a recessed static control and the TMWCCButton
  41.     object).
  42.  
  43.     I hope you find Wintask useful.
  44.  
  45.     Jeff...
  46.  
  47. ***}
  48.  
  49. program WinTask;
  50.  
  51. {$R WinTask.res}
  52.  
  53. uses WinTypes, WinProcs, ShellAPI, Strings, ToolHelp, MObjects,
  54.          {$IFDEF Ver15}
  55.              WObjects;
  56.          {$ELSE}
  57.              Objects, OWindows, ODialogs;
  58.          {$ENDIF}
  59.  
  60. const
  61.  
  62.     {*** Button ID's ***}
  63.     idw_But1            = 201;
  64.     idw_But2            = 202;
  65.     idw_But3            = 203;
  66.     idw_But4            = 204;
  67.     idw_But5            = 205;
  68.  
  69.     {*** Window Control ID's ***}
  70.     idw_Listbox         = 401;
  71.     idw_Static          = 402;
  72.  
  73.     {*** Dialog Control ID's ***}
  74.     idd_Static1         = 403;
  75.     idd_Static2         = 404;
  76.  
  77.     {*** System Menu ID ***}
  78.     idm_About           = 701;
  79.  
  80.     {*** Speaks for itself ***}
  81.     AppName     : PChar = 'WinTask';
  82.  
  83. type
  84.  
  85.     PAboutDialog = ^TAboutDialog;
  86.     TAboutDialog = object(TSFXDialog)
  87.         {***
  88.  
  89.             TMWCCBmpButton is a BWCC style bitMap button object. TMWCCStatic is a static object
  90.             that displays either raised, recessed or normal static controls. WMDrawItem is required
  91.             to draw the TMWCCBmpButton ownerdraw button object.
  92.  
  93.         ***}
  94.         OkBut : PMWCCBmpButton;
  95.         Stat  : PMWCCStatic;
  96.         constructor Init (AParent: PWindowsObject; AName: PChar);
  97.         procedure SetUpWindow; virtual;
  98.         procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
  99.     end;
  100.  
  101.     PWinTaskWindow = ^TWinTaskWindow;
  102.     TWinTaskWindow = object(TSFXWindow)
  103.         {***
  104.  
  105.             TSFXWindow is a resizable 3D Window object. It doesn't support normal menu's or
  106.             TScroller scroll bars. If you don't want the window to be resized set IsSizeable
  107.             in the constructor to False. For a resizeable window set it to True.
  108.  
  109.             TMWCCListBox displays a recessed list box with a vertical scroll bar.
  110.             TMWCCButton is a button object that can be used to display a single bitmap, text,
  111.             or both on a button. If the button is resizeable as in this example the text
  112.             (or bitmap) automatically recentres itself. The button can either be raised or
  113.             recessed.
  114.  
  115.         ***}
  116.         LB       : PMWCCListBox;
  117.         ST       : PMWCCStatic;
  118.         TaskProc : TFarproc;
  119.         AppIcon, WinIcon,    IcoHandle  : HIcon;
  120.         But1, But2, But3, But4, But5 : PMWCCButton;
  121.         constructor Init(AParent: PWindowsObject; AName: PChar);
  122.         destructor Done; virtual;
  123.         function GetClassName : PChar; virtual;
  124.         procedure GetWindowClass (var AWndClass: TWndClass); virtual;
  125.         procedure SetUpWindow; virtual;
  126.         procedure WMSysCommand (var Msg: TMessage); virtual wm_First + wm_SysCommand ;
  127.         {*** WMMeasureItem  and WMDrawItem draw the list box ***}
  128.         procedure WMMeasureItem (var Msg: TMessage); virtual wm_First + wm_MeasureItem;
  129.         procedure WMDrawItem (var Msg: TMessage); virtual wm_First + wm_DrawItem;
  130.         procedure WMSize (var Msg: TMessage); virtual wm_First + wm_Size;
  131.         procedure ListWindows; virtual;
  132.         procedure IDWListbox (var Msg: TMessage); virtual id_First + idw_ListBox;
  133.         procedure IDWBut1 (var Msg: TMessage); virtual id_First + idw_But1;
  134.         procedure IDWBut2 (var Msg: TMessage); virtual id_First + idw_But2;
  135.         procedure IDWBut3 (var Msg: TMessage); virtual id_First + idw_But3;
  136.         procedure IDWBut4 (var Msg: TMessage); virtual id_First + idw_But4;
  137.         procedure IDWBut5 (var Msg: TMessage); virtual id_First + idw_But5;
  138.     end;
  139.  
  140.     PWinTaskApplication = ^TWinTaskApplication;
  141.     TWinTaskApplication = object(TApplication)
  142.         procedure InitMainWindow; virtual;
  143.     end;
  144.  
  145. var
  146.  
  147.     IsTopWindows : Boolean;
  148.  
  149.  
  150. {********** TWinTaskApplication **********}
  151.  
  152. procedure TWinTaskApplication.InitMainWindow;
  153. {*** True produces a resizeable window ***}
  154. begin
  155.     MainWindow := New(PWinTaskWindow, Init(nil, 'Task List'));
  156. end;
  157.  
  158. {********** Callback function to list windows **********}
  159.  
  160. function GetTaskProc(Wnd: HWnd; LB: PMWCCListbox): Boolean; export;
  161. {***
  162.  
  163.     This is the function that actually enumerates all the windows. When the function name
  164.     is set to true the function continues to enumerate all the window giving you a handle
  165.     for each one (Wnd). Here I use the handle to get the window's title and add it to the
  166.     list box. If IsTopWindows is True only Top windows are listed. If its False all windows
  167.     are listed.
  168.  
  169. ***}
  170. var
  171.     Buf: array[0..79] of Char;
  172. begin
  173.     GetTaskProc := True;
  174.     GetWindowText(Wnd, Buf, sizeof(Buf));
  175.     if (Buf[0] <> #0) and (StrIComp(Buf, 'Task List') <> 0) then
  176.     begin
  177.         if IsTopWindows then
  178.             if  (GetWindow(Wnd, gw_Owner) = 0) then
  179.                 LB^.AddString(Buf);
  180.         if not IsTopWindows then
  181.             LB^.AddString(Buf);
  182.     end;
  183. end;
  184.  
  185. {********** TWinTaskWindow **********}
  186.  
  187. constructor TWinTaskWindow.Init (AParent: PWindowsObject; AName: PChar);
  188. {***
  189.  
  190.     The list box, static and button objects are initialized with zero values because
  191.     WMSize sets their position later.
  192.  
  193. ***}
  194. begin
  195.     TSFXWindow.Init(AParent, AName);
  196.     Attr.X := GetSystemMetrics(sm_CXScreen) div 4;
  197.     Attr.Y := (GetSystemMetrics(sm_CYScreen) div 4) + 5;
  198.     Attr.W := GetSystemMetrics(sm_CXScreen) div 2;
  199.     Attr.H := (GetSystemMetrics(sm_CYScreen) div 2) - 10;
  200.     LB := New(PMWCCListBox, Init(@Self, idw_ListBox, 0, 0, 0, 0, True));
  201.     {*** This sets the list box style to Ownerdraw, HasStrings and WantKeyboardInput ***}
  202.     LB^.Attr.Style := LB^.Attr.Style or lbs_OwnerDrawVariable or lbs_HasStrings
  203.                                         or lbs_WantKeyboardInput;
  204.     ST := New(PMWCCStatic, Init(@Self, idw_Static, '', 0, 0, 0, 0, 0, ctl_Recessed, False));
  205.     But1 := New(PMWCCButton, Init(@Self, idw_But1, 'All Windows', 0, 0, 0, 0, nil, 0));
  206.     But2 := New(PMWCCButton, Init(@Self, idw_But2, 'Top Windows', 0, 0, 0, 0, nil, 0));
  207.     But3 := New(PMWCCButton, Init(@Self, idw_But3, 'Show', 0, 0, 0, 0, nil, 0));
  208.     But4 := New(PMWCCButton, Init(@Self, idw_But4, 'Hide', 0, 0, 0, 0, nil, 0));
  209.     But5 := New(PMWCCButton, Init(@Self, idw_But5, 'End Task', 0, 0, 0, 0, nil, 0));
  210.     AppIcon := LoadIcon(HInstance, 'WinTask');
  211.     WinIcon := LoadIcon(HInstance, 'Windows');
  212.     {*** This sets IsTopWindows to true so that only top Windows are initially displayed ***}
  213.     IsTopWindows := True;
  214. end;
  215.  
  216. destructor TWinTaskWindow.Done;
  217. begin
  218.     DeleteObject(AppIcon);
  219.     DeleteObject(WinIcon);
  220.     TSFXWindow.Done;
  221. end;
  222.  
  223. function TWinTaskWindow.GetClassName;
  224. begin
  225.     GetClassName := AppName;
  226. end;
  227.  
  228. procedure TWinTaskWindow.GetWindowClass (var AWndClass: TWndClass);
  229. begin
  230.     TSFXWindow.GetWindowClass(AWndClass);
  231.     AWndClass.HIcon := AppIcon;
  232. end;
  233.  
  234. procedure TWinTaskWindow.SetUpWindow;
  235. var
  236.     SysMenu : HMenu;
  237. begin
  238.     TSFXWindow.SetUp